<template>
  <el-button type="primary" v-if="showButtin" size="mini" @click="handleConfirm">
    确认订单
  </el-button>
</template>

<script>
export default {
  name: 'ConfirmButton',
  props: {
    row: {
      type: Object,
      default: () => ({})
    },
    userInfo: {
      type: Object,
      default: () => ({})
    },
    orderStatusJson: {
      type: Array,
      default: () => []
    },
    orderTypeJson: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      showButtin: false,
    }
  },
  watch: {
    row(val) {
      this.$nextTick(() => {
        this.isShow()
      })
    },
    userInfo(val) {
      this.$nextTick(() => {
        this.isShow()
      })
    }
  },
  created() {
    this.$nextTick(() => {
      this.isShow()
    })
  },
  methods: {
    isShow() {
      //状态
      if (this.row.status !== 1 || !this.checkButtonPermission('confirm') || this.row.type === 1) {
        this.showButtin = false
        return false
      }
      let typeIndex = -1;
      this.orderTypeJson.some((item, index) => {
        if (this.row.type === item.value) {
          typeIndex = index;
          return true
        }
      });
      //类型
      if (typeIndex === -1) {
        this.showButtin = false
        return false
      }
      //判断用户类型
      // const userTypeOk = this.orderTypeJson[typeIndex].confirmOrderUser && this.orderTypeJson[typeIndex].confirmOrderUser.includes(this.userInfo.type)
      // if (userTypeOk) {
      this.showButtin = true
      // } else {
      //   this.showButtin = false
      // }
    },
    handleConfirm() {
      this.$emit('handleConfirm', this.row)
    }
  }
}
</script>
